﻿Imports System.Data
Imports System.Data.SqlClient
Public Class NguoiThueNha_DAO
    Public Shared Function ChenDuLieuNguoiThue(ByVal NguoiThue As NguoiThueNha_DTO) As Boolean
        Dim cn As SqlConnection = DataProvider.KetNoi()
        Dim check As Boolean = True
        Dim cm As SqlCommand = New SqlCommand("ThemNguoiThue", cn)
        cm.CommandType = CommandType.StoredProcedure
        cm.Parameters.AddWithValue("@Hoten", NguoiThue.TenNguoiThue)
        cm.Parameters.AddWithValue("@Diachi", NguoiThue.DiaChi)
        cm.Parameters.AddWithValue("@Dienthoai", NguoiThue.DienThoai)
        cm.Parameters.AddWithValue("@Diadiem", NguoiThue.DiaDiem)
        cm.Parameters.AddWithValue("@Maloainha", NguoiThue.MaLoaiNha)
        cm.Parameters.AddWithValue("@giamax", NguoiThue.GiaMax)
        cm.Parameters.AddWithValue("@giamin", NguoiThue.GiaMin)
        cm.Parameters.AddWithValue("@CMND", NguoiThue.CMND)

        Try
            cm.ExecuteNonQuery()

            cn.Close()
        Catch ex As Exception
            cn.Close()
            check = False

        End Try
        Return (check)
    End Function
    Public Shared Function LoadNguoiThue() As DataTable
        Dim cn As SqlConnection = DataProvider.KetNoi()

        Dim cm As SqlCommand = New SqlCommand("LoadNguoiThueNha", cn)
        cm.CommandType = CommandType.StoredProcedure
        Dim da As SqlDataAdapter = New SqlDataAdapter(cm)
        Dim bang As DataTable = New DataTable()
        da.Fill(bang)
        cn.Close()
        Return bang
    End Function
    Public Shared Function LoadTenNguoiThue() As DataTable
        Dim cn As SqlConnection = DataProvider.KetNoi()
        Dim cm As SqlCommand = New SqlCommand("LoadTenNguoiThue", cn)
        cm.CommandType = CommandType.StoredProcedure
        Dim da As SqlDataAdapter = New SqlDataAdapter(cm)
        Dim bang As DataTable = New DataTable()
        da.Fill(bang)
        cn.Close()
        Return bang
    End Function
    Public Shared Function updateNguoiThue(ByVal NguoiThue As NguoiThueNha_DTO) As Boolean
        Dim cn As SqlConnection = DataProvider.KetNoi()
        Dim check As Boolean = True
        Dim cm As SqlCommand = New SqlCommand("updateNguoiThue", cn)
        cm.CommandType = CommandType.StoredProcedure
        cm.Parameters.AddWithValue("@ma", NguoiThue.MaNguoiThue)
        cm.Parameters.AddWithValue("@hoten", NguoiThue.TenNguoiThue)
        cm.Parameters.AddWithValue("@diachi", NguoiThue.DiaChi)
        cm.Parameters.AddWithValue("@dienthoai", NguoiThue.DienThoai)
        cm.Parameters.AddWithValue("@diadiem", NguoiThue.DiaDiem)
        cm.Parameters.AddWithValue("@tenloainha", NguoiThue.TenLoaiNha)
        cm.Parameters.AddWithValue("@giamax", NguoiThue.GiaMax)
        cm.Parameters.AddWithValue("@giamin", NguoiThue.GiaMin)
        cm.Parameters.AddWithValue("@cmnd", NguoiThue.CMND)


        Try
            cm.ExecuteNonQuery()

            cn.Close()
        Catch ex As Exception
            cn.Close()
            check = False

        End Try
        Return (check)
    End Function
    Public Shared Function xoaNguoiThue(ByVal NguoiThue As String) As Boolean
        Dim cn As SqlConnection = DataProvider.KetNoi()
        Dim check As Boolean = True
        Dim cm As SqlCommand = New SqlCommand("xoanguoithue", cn)
        cm.CommandType = CommandType.StoredProcedure
        cm.Parameters.AddWithValue("@maNt", NguoiThue)
        Try
            cm.ExecuteNonQuery()

            cn.Close()
        Catch ex As Exception
            cn.Close()
            check = False

        End Try
        Return (check)
    End Function
    Public Shared Function ChenNguoiThueTuExcel(ByVal NguoiThue As NguoiThueNha_DTO) As Boolean
        Dim cn As SqlConnection = DataProvider.KetNoi()
        Dim check As Boolean = True
        Dim cm As SqlCommand = New SqlCommand("ChenDuLieuTuExcelNguoiThue", cn)
        cm.CommandType = CommandType.StoredProcedure
        'cm.Parameters.AddWithValue("@ma", NguoiThue.MaNguoiThue)
        cm.Parameters.AddWithValue("@hoten", NguoiThue.TenNguoiThue)
        cm.Parameters.AddWithValue("@diachi", NguoiThue.DiaChi)
        cm.Parameters.AddWithValue("@dienthoai", NguoiThue.DienThoai)
        cm.Parameters.AddWithValue("@diadiem", NguoiThue.DiaDiem)
        cm.Parameters.AddWithValue("@tenloainha", NguoiThue.TenLoaiNha)
        cm.Parameters.AddWithValue("@giamax", NguoiThue.GiaMax)
        cm.Parameters.AddWithValue("@giamin", NguoiThue.GiaMin)
        cm.Parameters.AddWithValue("@cmnd", NguoiThue.CMND)
        Try
            cm.ExecuteNonQuery()

            cn.Close()
        Catch ex As Exception
            cn.Close()
            check = False

        End Try
        Return check
    End Function
End Class
